package com.zn.kjj.util.web;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.util.WebUtils;

/**
 * .
 * @ClassName: WebUtils
 * @Description: 工具类
 * @author w15579
 * 2017年2月24日
 * @version v1.0.0
 */
public class PreWebUtils extends WebUtils{
    /**
     * .
     * @Title: toHttpRequest
     * @Description: 转换成Http请求
     * @param request .
     * @return http
     * @since v1.0.0
     */
    public static HttpServletRequest toHttpRequest(ServletRequest request) {
        return (HttpServletRequest) request;
    }
    /**
     * .
     * @Title: toHttpResponse
     * @Description: 转换成Http响应
     * @param response 。
     * @return 参数说明
     * @since v1.0.0
     */
    public static HttpServletResponse toHttpResponse(ServletResponse response) {
        return (HttpServletResponse) response;
    }
    /**
     * .
     * @Title: isAjaxRequest
     * @Description: 判断Http请求是否为异步请求
     * @param request .
     * @return true or false
     * @since v1.0.0
     */
    public static boolean isAjaxRequest(HttpServletRequest request) {
        if (request.getHeader("x-requested-with") != null
                && "XMLHttpRequest".equalsIgnoreCase(request.getHeader("x-requested-with"))) {
            return true;
        }
        return false;
    }
    /**
     * .
     * @Title: isContains
     * @Description: 判断是否包含
     * @param container 地址
     * @param regx 校验串
     * @return true or false
     * @since v1.0.0
     */
    public static boolean isContains(String container, String[] regx) {
        boolean result = false;
        for (int i = 0; i < regx.length; i++) {
            if (container.indexOf(regx[i]) != -1) {
                return true;
            }
        }
        return result;
    }

}
